package com.tian.excel.controller;


import com.tian.excel.entity.Dept;
import com.tian.excel.service.DeptService;
import com.tian.excel.vo.DeptVo;
import com.tian.excel.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/7/14/11:41
 */
@RestController
@Api(tags = "部门管理")
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    DeptService deptService;


    @GetMapping("/hello")
    @ApiOperation("hello")
    @PreAuthorize("hasAuthority('dept:hello')")
    public String hello(){
        return "hello";
    }


   @PostMapping("/getDept")
   @ApiOperation("多条件查询部门信息")
   @ApiImplicitParam(name = "deptVo" ,value = "查询部门信息的条件",required = true,dataType = "DeptVo")
   public R selectDept(@RequestBody DeptVo deptVo){
       return deptService.selectAll(deptVo);
   }

   @PostMapping("/insertDept")
   @ApiOperation("添加部门信息")
   @ApiImplicitParam(name = "dept" ,value = "部门信息",required = true,dataType = "Dept")
   public R insertDept(@RequestBody Dept dept){
       return deptService.insertDept(dept);
   }

   @PutMapping("/updateDept")
   @ApiOperation("修改部门信息")
   @ApiImplicitParam(name = "dept" ,value = "部门信息",required = true,dataType = "Dept")
   public R updateDept(@RequestBody Dept dept){
       return deptService.updateById(dept);
   }

   @DeleteMapping("/deletDept/{id}")
   @ApiOperation("根据部门编号删除部门信息")
   @ApiImplicitParam(name = "id" ,value = "部门编号",required = true,dataType = "int")
   public R deleteById(@PathVariable int id){
       return deptService.deleteById(id);
   }

}
